game_manager_lib\commands\metadata/
search.rs

1//! Comandos para busca de metadados externos
2//!
3//! Permite buscar detalhes de jogos, listas de tendências e giveaways
4//! usando APIs externas como RAWG e GamerPower.
5
6use crate::database;
7use crate::errors::AppError;
8use crate::services::gamerpower::{self, Giveaway};
9use crate::services::rawg;
10use tauri::AppHandle;
11
12/// Busca detalhes de um jogo na RAWG
13#[tauri::command]
14pub async fn fetch_game_details(
15    app: AppHandle,
16    query: String,
17) -> Result<rawg::GameDetails, AppError> {
18    let api_key = database::get_secret(&app, "rawg_api_key")?;
19    rawg::fetch_game_details(&api_key, query)
20        .await
21        .map_err(AppError::NetworkError)
22}
23
24/// Busca jogos em tendência no momento na RAWG
25#[tauri::command]
26pub async fn get_trending_games(app: AppHandle) -> Result<Vec<rawg::RawgGame>, AppError> {
27    let api_key = database::get_secret(&app, "rawg_api_key")?;
28    rawg::fetch_trending_games(&app, &api_key)
29        .await
30        .map_err(AppError::NetworkError)
31}
32
33/// Busca jogos que serão lançados em breve na RAWG
34#[tauri::command]
35pub async fn get_upcoming_games(app: AppHandle) -> Result<Vec<rawg::RawgGame>, AppError> {
36    let api_key = database::get_secret(&app, "rawg_api_key")?;
37    rawg::fetch_upcoming_games(&app, &api_key)
38        .await
39        .map_err(AppError::NetworkError)
40}
41
42/// Busca giveaways ativos na GamerPower
43#[tauri::command]
44pub async fn get_active_giveaways(app: AppHandle) -> Result<Vec<Giveaway>, AppError> {
45    gamerpower::fetch_giveaways(&app)
46        .await
47        .map_err(AppError::NetworkError)
48}